@extends('steward.layoutEdit')

@section('css')
    <link rel="stylesheet" href="/static/libs/webuploader/webuploader.css" type="text/css"/>
    <style>
        .webuploader-pick {
            padding-top: 5px;
            margin-left: -10px;
            display: inline;
            float: left;
            margin-left: 0;

        }
        .form-control{
            display: inline;
            zoom:1;
            padding:0;
        }
        .download{
            float:left;
        }
        .download input{
            display: inline;
            float: left;
        }
        .download .upto{
            float: left;
            display: inline;
            zoom:1;
        }
    </style>
@endsection

@section('title')
    <li class="cur">
        <span>价格上传</span>
    </li>
@endsection

@section('content')

    <div class="row">
        <div class="col-lg-12">
            <span>价格批量上传</span>
        </div>
        <div style="height:50px;"></div>
        <div class="col-lg-12">
            <div class="row col-md-12">
                <div class="col-md-5 download">
                    <input type="text" id="file" class="form-control col-md-3" style="width: 200px;margin-left: 100px;">
                    <div class="option_img col-md- upto" id="file_upload" style="height:34px;">浏览</div>
                </div>
                <div class="col-md-6" style="margin-left: -50px;">
                    <button class="btn btn-primary" id="batch_do" type="button">上传</button>
                    <button class="btn btn-primary" id="re-export" type="button" onclick="dw()">模板下载</button>
                </div>
            </div>
        </div>
    </div><br>

@endsection

@section('js')

    <script src="/static/libs/webuploader/webuploader.js"></script>
    <script>

        //下载模板
        function dw () {
            window.location.href = '/lar/steward/price/export';
        }

        //选择文件
        var uploader = WebUploader.create({
            auto: true,
            swf: '/static/libs/webuploader/Uploader.swf',
            server: '/lar/upload?action=goods/upload',
            pick: '#file_upload',
            resize: false,
            duplicate :true
        });

        uploader.on( 'uploadSuccess', function(  file,res ) {
            if (res.code == 200) {
                layer.msg('文件已选择成功',{icon:1,time:1000});
                $('#file').val(res.data.name).attr('data-url',res.data.url);
            } else {
                layer.msg(res.message,{icon: 2,shade: [0.15, 'black'],offset:'120px',time:1000});
            }
        });

        //批量上传
        $(document).on('click','#batch_do', function () {
            if(!$('#file').val()){
                layer.msg('请先选择文件',{icon:2,time:1000});
                return false;
            }
            var file_url = $('#file').attr('data-url');
            $.ajax({
                type : 'get',
                url :'/lar/steward/price/batch_do',
                dataType : 'json',
                data : {'file_url':file_url},
                success : function (o) {
                    if(o.code == 200){
                        layer.msg(o.message,{icon:1,time:1000});
                        $('#file').val('');
                    }else{
                        layer.msg('上传失败',{icon:2,time:1000});
                        $('#file').val('');
                    }
                }
            });
        })
    </script>

@endsection